<div id="main">
	<div class="hr">
		<hr />
	</div>
	<div id="example">
	<?php
	require 'conn.php';
	$shopId = $_GET['shopid'];

	global $query;
	$query = "SELECT * FROM images";

	if (isset($_GET['page'])) {
		$page = intval($_GET['page']);
	}
	else
	{
		$page = 1;
	}
	$page_count = 0;
	$page_size = $psize;
	$query1 = "SELECT count(*) FROM images WHERE shop_id=".$shopId;
	$result = mysql_query($query1);
	$row = mysql_fetch_row($result);
	$amount = $row[0];
	if ($amount) {
		if ($amount < $page_size) {
			$page_count = 1;
		}
		if ($amount % $page_size) {
			$page_count = (int)($amount / $page_size) + 1;
		}
		else
		{
			$page_count = $amount / $page_size;
		}
	}
	else
	{
		$page_count = 0;
	}

	echo "<h2> 图片列表 </h2>";
	echo "<blockquote>";
	echo "<p>管理员可以查看和删除以下图片</p>";
	echo "</blockquote>";
	echo "<table border=1>";
	echo "<tr>";
	echo "<td>编号</td>";
	echo "<td>图片</td>";
	echo "<td colspan=2>操作</td>";
	echo "</tr>";

	if ($amount) {
		$query2 = $query." WHERE shop_id=".$shopId." order by image_id desc limit ". ($page - 1)*$page_size .", $page_size";
		$result = mysql_query($query2);
		$num = mysql_num_rows($result);
		for ($i = 0; $i < $num; $i++) {
			$row = mysql_fetch_array($result);
			$id = $row['image_id'];
			$imageurl=$row['imageurl'];
			$thumbimageurl = $row['thumb_imageurl'];

			echo "<tr>";
			echo "<td>".$id."</td>";
			echo "<td><image src='".$thumbimageurl."'/></td>";
			echo "<td>";
			echo "<form action='deleteImage.php' method='post'>";
			echo "<input type='hidden' name='deleteid' value='$id'/>";
			echo "<input type='hidden' name='shopid' value='$shopId'/>";
			echo "<input type='hidden' name='imageurl' value='$imageurl'/>";
			echo "<input type='hidden' name='thumbimageurl' value='$thumbimageurl'/>";
			echo "<input type='submit' value='删除'/>";
			echo "</form>";
			echo "</td>";

			echo "<td>";
			echo "<form id='form1' method='post' enctype='multipart/form-data' action='uploadEditImage.php'>";
			echo "<input id='file' type='file'' name='file'> ";
			echo "<input name='scan' type='hidden' id='up' value='true'>";
			echo "<br/><input type='submit' name='imagesubmit' value='修改图片'>";

			echo "<input type='hidden' name='shopid' value='$shopId'/>";
			echo "<input name='imageid' type='hidden' value=$id>";
			echo "<input name='thumbimage' type='hidden' value=$thumbimageurl]>";
			echo "<input name='image' type='hidden' value=$imageurl>";
			echo "</form>";
			echo "</td>";

			echo "</tr>";
		}

	}

	else
	{
		echo "没有记录";
	}

	echo "</table>";

	$page_string = '';
	if ($page == 1) {
		$page_string .= '第一页|上一页';
	}
	else
	{
		$page_string .= '<a href=?page=1&shopid='.$shopId.'>第一页</a>|<a href=?page='.($page - 1).'&shopid='.$shopId.'>上一页</a>|';
	}
	if (($page == $page_count) || ($page_count == 0)) {
		$page_string .= '下一页|尾页';
	}
	else
	{
		$page_string .= '<a href=?page='.($page + 1).'&shopid='.$shopId.'>下一页</a>|<a href=?page='.$page_count.'&shopid='.$shopId.'>尾页</a>|';
	}
	echo "<br>".$page_string;

	echo "<br>";
	echo "<hr>";
	echo "<h3>添加图片<h3/>";
	echo "<hr>";
	echo "<form id='form1' method='post' enctype='multipart/form-data' action='uploadImage.php'>";
	echo "<input id='file' type='file'' name='file'> ";
	echo "<input name='scan' type='hidden' id='up' value='true'>";
	echo "<br/><input type='submit' name='imagesubmit' value='添加图片'>";

	echo "<input type='hidden' name='shopid' value='$shopId'/>";
	echo "</form>";
	echo "</td>";
	?>

	</div>
</div>
